﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Web;
using System.Net;
using System.IO;
using System.Collections;
using System.Timers;
using System.Collections.ObjectModel;
using System.Text.RegularExpressions;
namespace BallData
{
    public class Bet007_NetDataHelper
    {
        public static Bet007_MatchData bet007_matchdataobj = new Bet007_MatchData();

        public static MainUIControl mainuicontrol = null;

        public static Bet007_AnalysisTest analysistest = new Bet007_AnalysisTest();
        
        /// <summary>
        /// 获得当天比赛现场数据
        /// </summary>
        /// <returns></returns>
        public static void GetMatchdataFromtitan007()
        {
            StringBuilder strbuilder = new StringBuilder();
            strbuilder.Append("http://bf.titan007.com/vbsxml/bfdata.js?");
            strbuilder.Append(Convert.ToUInt64(OddsUntil.ConvertDateTimeInt(DateTime.Now)) * 1000);



            String matchdata;
            HttpWebRequest httprequest = (HttpWebRequest)WebRequest.Create(strbuilder.ToString());
            httprequest.Timeout = 30000;
            httprequest.Referer = "http://bf.titan007.com";
            //httprequest.ContentType = "text/javascript; charset=gb2312";
            //httprequest.ContentType = "text/html; charset=utf-8";
            HttpWebResponse response = null;
            try
            {
                response = (HttpWebResponse)httprequest.GetResponse();

                StreamReader sr = new StreamReader(response.GetResponseStream(), System.Text.Encoding.GetEncoding("gb2312"));
                // 得到赛事数据
                matchdata = sr.ReadToEnd();
                sr.Close();
                response.Close();
            }
            catch (System.Exception ex)
            {
                Console.Write(ex.Message);
                return;
            }



           

            MatchCollection mc;
            Regex r = new Regex("A\\[\\d+\\]=(\".*#.*\")"); //定义一个Regex对象实例
            mc = r.Matches(matchdata);

            for (int i = 0; i < mc.Count; i++)
            {
                // 取=引号里面的
                String line = mc[i].Value.Substring(mc[i].Value.IndexOf('=') + 2, mc[i].Value.Length - 3 - mc[i].Value.IndexOf('='));
                Titan007MatchData titanmatchdata = new Titan007MatchData(line);
                bet007_matchdataobj.Titan007MatchData.Add(titanmatchdata.mId, titanmatchdata);
            }

            Regex r2 = new Regex("B\\[\\d+\\]=(\".*\")"); //定义一个Regex对象实例
            mc = r2.Matches(matchdata);

            for (int i = 0; i < mc.Count; i++)
            {
                // 取=引号里面的
                String line = mc[i].Value.Substring(mc[i].Value.IndexOf('=') + 2, mc[i].Value.Length - 3 - mc[i].Value.IndexOf('='));
                Titan007MatchTeam team = new Titan007MatchTeam(line);
                if (!Titan007Until.Titan007MatchTeam.Contains(team.cnName))
                {
                    Titan007Until.Titan007MatchTeam.Add(team.cnName, team);
                }

            }

            Regex r3 = new Regex("C\\[\\d+\\]=\\[(.*)\\];"); //定义一个Regex对象实例
            mc = r3.Matches(matchdata);

            for (int i = 0; i < mc.Count; i++)
            {
                // 取=引号里面的
                String line = mc[i].Value.Substring(mc[i].Value.IndexOf("=[") + 2, mc[i].Value.Length - 4 - mc[i].Value.IndexOf("=["));
                Titan007League team = new Titan007League(line);
                Titan007Until.Titan007League.Add(team.lId, team);
            }

        }

        /// <summary>
        /// 获得当天比赛现场数据结束调用
        /// </summary>
        /// <param name="asyncResult"></param>
        /// <returns></returns>
        public static void GetMatchdataFromtitan007Ok(IAsyncResult asyncResult)
        {
            //(asyncResult.AsyncState as Action).EndInvoke(asyncResult);
            //this.Dispatcher.BeginInvoke((Action)(() =>
            //{
            //    this.logList.Add("获取Titan007赛事数据OK!");
            //}));

        }
        
        /// <summary>
        /// bet007.com 获取当天对阵球队名字数据页面
        /// </summary>
        /// <returns></returns>
        public static void GetMatchAliasDataFromtitan007()
        {
            StringBuilder strbuilder = new StringBuilder();
            strbuilder.Append("http://bf.bet007.com/vbsxml/alias.js");


            HttpWebRequest httprequest = (HttpWebRequest)WebRequest.Create(strbuilder.ToString());
            httprequest.Timeout = 30000;
            httprequest.Referer = "http://bf.bet007.com";
            HttpWebResponse response = null;
            try
            {
                response = (HttpWebResponse)httprequest.GetResponse();
            }
            catch (System.Exception ex)
            {
                Console.Write(ex.Message);
                return;
            }



            StreamReader sr = new StreamReader(response.GetResponseStream(), System.Text.Encoding.GetEncoding("gb2312"));
            // 得到赛事数据
            String matchdata = sr.ReadToEnd();
            sr.Close();
            response.Close();

            MatchCollection mc;
            Regex r3 = new Regex("T\\[\\d+\\]=\"(.*)\""); //定义一个Regex对象实例
            mc = r3.Matches(matchdata);

            for (int i = 0; i < mc.Count; i++)
            {
                // 取=引号里面的
                String line = mc[i].Value.Substring(mc[i].Value.IndexOf("=\"") + 2, mc[i].Value.Length - 3 - mc[i].Value.IndexOf("=\""));
                Titan007Alias team = new Titan007Alias(line);
            }
        }

        /// <summary>
        /// bet007.com 获取当天对阵球队名字数据页面 结束调用
        /// </summary>
        /// <param name="asyncResult"></param>
        /// <returns></returns>
        public static void GetMatchAliasDataFromtitan007Ok(IAsyncResult asyncResult)
        {
            //(asyncResult.AsyncState as Action).EndInvoke(asyncResult);
            //this.Dispatcher.BeginInvoke((Action)(() =>
            //{
            //    this.logList.Add("获取Titan007赛事数据OK!");
            //}));

        }

        /// <summary>
        /// bet007.com 获取当前比赛盘路数据
        /// </summary>
        /// <returns></returns>
        public static void GetMatchPanluFromtitan007()
        {
            StringBuilder strbuilder = new StringBuilder();
            strbuilder.Append("http://live3.titan007.com/vbsxml/panlu.js");


            HttpWebRequest httprequest = (HttpWebRequest)WebRequest.Create(strbuilder.ToString());


            HttpWebResponse response = null;
            String matchdata = null;
            try
            {
                response = (HttpWebResponse)httprequest.GetResponse();

                StreamReader sr = new StreamReader(response.GetResponseStream(), System.Text.Encoding.GetEncoding("gb2312"));
                // 得到赛事数据
                matchdata = sr.ReadToEnd();
                sr.Close();
                response.Close();
            }
            catch (System.Exception ex)
            {
                Console.Write(ex.Message);
                return;
            }





            MatchCollection mc;
            Regex r3 = new Regex("p\\[\\d+\\]=(.*);"); //定义一个Regex对象实例
            mc = r3.Matches(matchdata);

            for (int i = 0; i < mc.Count; i++)
            {
                // 取=引号里面的
                String line = mc[i].Value.Substring(mc[i].Value.IndexOf("=[") + 2, mc[i].Value.Length - 3 - mc[i].Value.IndexOf("=["));
                Titan007Panlu team = new Titan007Panlu(line);
            }

        }

        /// <summary>
        /// bet007足球指数页面获取 根据博彩公司id (1,17,8,3,31)
        /// </summary>
        /// <returns></returns>
        public static void GetCurMathDayMatchOdds()
        {
            StringBuilder strurl = new StringBuilder();

            strurl.Append("http://61.143.225.74:88/xml/odds.aspx?companyID=");
            strurl.Append("1,17,8,3,31");


            HttpWebRequest httprequest = (HttpWebRequest)WebRequest.Create(strurl.ToString());
            httprequest.Timeout = 30000;
            httprequest.Referer = "http://61.143.225.74:88/";
            HttpWebResponse response = null;
            String matchdata = null;
            try
            {
                response = (HttpWebResponse)httprequest.GetResponse();

                StreamReader sr = new StreamReader(response.GetResponseStream());
                // 得到赛事数据
                matchdata = sr.ReadToEnd();
                sr.Close();
                response.Close();
            }
            catch (System.Exception ex)
            {
                Console.Write(ex.Message);
                return;
            }


            String[] domains = matchdata.Split(OddsUntil.Bet007_SplitDomain);

            String[] leagueDomain = domains[0].Split(OddsUntil.Bet007_SplitRecord);

            for (var i = 0; i < leagueDomain.Length; i++)
            {
                Bet007_LeagueItem leagueItem = new Bet007_LeagueItem(leagueDomain[i]);

                if(!Bet007_NetDataHelper.bet007_matchdataobj.LeagueList.ContainsKey(leagueItem.lId))
                    Bet007_NetDataHelper.bet007_matchdataobj.LeagueList.Add(leagueItem.lId, leagueItem);
            }



            //处理亚赔数据域
            String[] oddsDomain = domains[2].Split(OddsUntil.Bet007_SplitRecord);
            for (int i = 0; i < oddsDomain.Length; i++)
            {
                Bet007_OddsAsian oddsItem = new Bet007_OddsAsian(oddsDomain[i]);
                bet007_matchdataobj.Odds1List.Add(oddsItem.mId + "_" + oddsItem.cId, oddsItem);
            }
            //处理欧赔数据域
            oddsDomain = domains[3].Split(OddsUntil.Bet007_SplitRecord);
            for (int i = 0; i < oddsDomain.Length; i++)
            {
                Bet007_Odds1x2 oddsItem = new Bet007_Odds1x2(oddsDomain[i]);
                bet007_matchdataobj.Odds2List.Add(oddsItem.mId + "_" + oddsItem.cId, oddsItem);
            }
            //处理大小球数据域
            oddsDomain = domains[4].Split(OddsUntil.Bet007_SplitRecord);
            for (int i = 0; i < oddsDomain.Length; i++)
            {
                Bet007_OddsOU oddsItem = new Bet007_OddsOU(oddsDomain[i]);
                bet007_matchdataobj.Odds3List.Add(oddsItem.mId + "_" + oddsItem.cId, oddsItem);
            }

            String[] matchDomain = domains[1].Split(OddsUntil.Bet007_SplitRecord);
            //matchdata.MatchNum = 0;

            for (int i = 0; i < matchDomain.Length; i++)
            {
                Bet007_Match match = new Bet007_Match(matchDomain[i]);
                bet007_matchdataobj.MatchList.Add(match.mId, match);
            }

        }

        /// <summary>
        /// bet007足球指数页面获取 根据博彩公司id (1,17,8,3,31) 结束调用
        /// </summary>
        /// <param name="asyncResult"></param>
        /// <returns></returns>
        public static void GetCurMathDayMatchOddsOk(IAsyncResult asyncResult)
        {
            


        }

        public static void GetHistoryMatchOdds()
        {
            DateTime now = DateTime.Now;

            String matchdata = WebUtil.getDataByUrl("http://vip.bet007.com/history/oddsData.aspx?date=" + now.ToString("yyyy-MM-dd"),System.Text.Encoding.GetEncoding("gb2312"));

            if (matchdata.Length < 10)
                return;

            String[] domains = matchdata.Split(OddsUntil.Bet007_SplitDomain);

            String[] leagueDomain = domains[0].Split(OddsUntil.Bet007_SplitRecord);

            for (var i = 0; i < leagueDomain.Length; i++)
            {
                Bet007_LeagueItem leagueItem = new Bet007_LeagueItem(leagueDomain[i]);

                if (!Bet007_NetDataHelper.bet007_matchdataobj.LeagueList.ContainsKey(leagueItem.lId))
                    Bet007_NetDataHelper.bet007_matchdataobj.LeagueList.Add(leagueItem.lId, leagueItem);
            }



            //处理亚赔数据域
            String[] oddsDomain = domains[2].Split(OddsUntil.Bet007_SplitRecord);
            for (int i = 0; i < oddsDomain.Length; i++)
            {
                Bet007_OddsAsian oddsItem = new Bet007_OddsAsian(oddsDomain[i]);
                bet007_matchdataobj.Odds1List.Add(oddsItem.mId + "_" + oddsItem.cId, oddsItem);
            }
            //处理欧赔数据域
            oddsDomain = domains[3].Split(OddsUntil.Bet007_SplitRecord);
            for (int i = 0; i < oddsDomain.Length; i++)
            {
                Bet007_Odds1x2 oddsItem = new Bet007_Odds1x2(oddsDomain[i]);
                bet007_matchdataobj.Odds2List.Add(oddsItem.mId + "_" + oddsItem.cId, oddsItem);
            }
            //处理大小球数据域
            oddsDomain = domains[4].Split(OddsUntil.Bet007_SplitRecord);
            for (int i = 0; i < oddsDomain.Length; i++)
            {
                Bet007_OddsOU oddsItem = new Bet007_OddsOU(oddsDomain[i]);
                bet007_matchdataobj.Odds3List.Add(oddsItem.mId + "_" + oddsItem.cId, oddsItem);
            }

            String[] matchDomain = domains[1].Split(OddsUntil.Bet007_SplitRecord);
            //matchdata.MatchNum = 0;

            for (int i = 0; i < matchDomain.Length; i++)
            {
                Bet007_Match match = new Bet007_Match(matchDomain[i]);
                bet007_matchdataobj.MatchList.Add(match.mId, match);
            }

        }

        public static void GetHistoryMatchOddsOk(IAsyncResult asyncResult)
        {



        }


        /// <summary>
        /// 请求网站数据初始化
        /// </summary>
        /// <param name="ui"></param>
        /// <returns></returns>
        public static void Init(MainUIControl ui)
        {
            mainuicontrol = ui;
            // 得到当前比赛比分页面
            Action action2 = GetMatchdataFromtitan007;
            action2.BeginInvoke(GetMatchdataFromtitan007Ok, action2);


            Action action3 = GetMatchAliasDataFromtitan007;
            action3.BeginInvoke(GetMatchAliasDataFromtitan007Ok, action3);



            Action action4 = GetCurMathDayMatchOdds;
            action4.BeginInvoke(GetMatchAliasDataFromtitan007Ok, action4);

            Action action5 = GetHistoryMatchOdds;
            action5.BeginInvoke(GetHistoryMatchOddsOk, action5);

            
        
        }

        /// <summary>
        /// 根据队伍名字获取赛事盘路
        /// </summary>
        /// <param name="Name"></param>
        /// <returns></returns>
        public static Bet007_Match GetMatchDataByName(String t1CnName, String t2CnName)
        {
            
            foreach (Bet007_Match bm in bet007_matchdataobj.MatchList.Values)
            {
                
                if (t1CnName.Length >= 2 && bm.t1CnName.StartsWith(t1CnName.Substring(0, 2)))
                {
                    if (t2CnName.Length >= 2 && bm.t2CnName.StartsWith(t2CnName.Substring(0, 2)))
                        return bm;
                }
                else if (t1CnName == bm.t1CnName && t2CnName == bm.t2CnName)
                {
                    return bm;
                }
            }

         

            return null;
        }


        /// <summary>
        /// 根据队伍英文名字获取赛事盘路
        /// </summary>
        /// <param name="Name"></param>
        /// <returns></returns>
        public static Bet007_Match GetMatchDataByEnName(String t1EnName, String t2EnName)
        {

            foreach (Bet007_Match bm in bet007_matchdataobj.MatchList.Values)
            {

                
                if (t1EnName.Length >= 2 && bm.t1EnName.StartsWith(t1EnName.Substring(0,2)))
                {
                    if (t2EnName.Length >= 2 && bm.t2EnName.StartsWith(t2EnName.Substring(0, 2)))
                        return bm;
                }
            }



            return null;
        }

        /// <summary>
        /// 根据队伍繁体名字获取赛事盘路
        /// </summary>
        /// <param name="Name"></param>
        /// <returns></returns>
        public static Bet007_Match GetMatchDataByTrName(String t1TrName, String t2TrName)
        {

            foreach (Bet007_Match bm in bet007_matchdataobj.MatchList.Values)
            {
                if (t1TrName.Length >= 2 && bm.t1TrName.StartsWith(t1TrName.Substring(0, 2)))
                {
                    if (t2TrName.Length >= 2 && bm.t2TrName.StartsWith(t2TrName.Substring(0, 2)))
                        return bm;
                }
            }



            return null;
        }

        /// <summary>
        /// 根据队伍名字获取赛事盘路
        /// </summary>
        /// <param name="Name"></param>
        /// <returns></returns>
        public static Titan007MatchData GetMatchData2ByName(String Name)
        {
            foreach (Titan007MatchData bm in bet007_matchdataobj.Titan007MatchData.Values)
            {
                if (Name == bm.t1CnName || Name == bm.t2CnName)
                {
                    return bm;
                }
            }
            return null;
        }



        public delegate String OnGetMatchHistoryData(String url);

        /// <summary>
        /// 获取对阵记录,联赛排名积分等信息
        /// </summary>
        /// <param name="mId"></param>
        /// <returns></returns>
        public static String GetMatchHistoryData(String mId)
        {
            if (bet007_matchdataobj.bet007analydata.ContainsKey(mId))
                return mId;
            Bet007_AnalysisData analydata = new Bet007_AnalysisData();

            bet007_matchdataobj.bet007analydata.Add(mId, analydata);

            HttpWebResponse responseodds = null;
            String oddsurl = String.Format("http://news.bet007.com/analysis/jsData/{0}.js?{1}", mId, Convert.ToInt64(OddsUntil.ConvertDateTimeInt(DateTime.Now)) * 1000);

            HttpWebRequest httprequestodds = (HttpWebRequest)WebRequest.Create(oddsurl);

            httprequestodds.ContentType = "text/html; charset=utf-8";

            String matchdataodds;
            try
            {
                responseodds = (HttpWebResponse)httprequestodds.GetResponse();

                StreamReader sr = new StreamReader(responseodds.GetResponseStream(), System.Text.Encoding.GetEncoding("gb2312"));
                // 得到赛事数据
                matchdataodds = sr.ReadToEnd();
                sr.Close();
                responseodds.Close();

            }
            catch (System.Exception ex)
            {
                Console.Write(ex.Message);
                return "0";
            }
            //Console.WriteLine(matchdataodds);

            // 得到当前博彩公司赔率
            MatchCollection mcodds;
            mcodds = Regex.Matches(matchdataodds, "\\[(?<cId>\\d+),\\[(?<startodds>[\\d,\\.]*)\\],?\\[(?<curodds>[\\d,\\.]*)\\]\\]");

            foreach (Match  mt in mcodds)
            {
                GroupCollection gc = mt.Groups;
                String cId = gc["cId"].Value ;
                Bet007_WebOdds startwedoods = new Bet007_WebOdds(gc["startodds"].Value);
                Bet007_WebOdds curwedoods = new Bet007_WebOdds(gc["curodds"].Value);
                analydata.oddscurlist.Add(cId + "startodds", startwedoods);
                analydata.oddscurlist.Add(cId + "curodds", curwedoods);
            }

            String url = "http://news.bet007.com/analysis/" + mId + "cn.htm";
            HttpWebRequest httprequest = (HttpWebRequest)WebRequest.Create(url);

            httprequest.ContentType = "text/html; charset=utf-8";

            HttpWebResponse response = null;

            String matchdata;
            try
            {
                response = (HttpWebResponse)httprequest.GetResponse();

                StreamReader sr = new StreamReader(response.GetResponseStream(), System.Text.Encoding.GetEncoding("gb2312"));
                // 得到赛事数据
                matchdata = sr.ReadToEnd();
                sr.Close();
                response.Close();

            }
            catch (System.Exception ex)
            {
                Console.Write(ex.Message);
                return "0";
            }

            
            

            MatchCollection mc;
            mc = Regex.Matches(matchdata, "var v_data=\\[.*\\];");//历史对阵成绩
            mc = Regex.Matches(mc[0].Value, "('\\d+-\\d+-\\d+',\\d+,'[\u4e00-\u9fa5]*','#[\\w]*',\\d+,'[<>\\w\\d\\s=/]*<span title=\"[\u4e00-\u9fa5\\s]*[:|：][\\w]*\">[\u4e00-\u9fa5\\w\\s\\d\\(\\)<>=/]*</span>[\u4e00-\u9fa5\\(\\)]*',\\d+,'<span title=\"[\u4e00-\u9fa5\\s]*[:|：][\\w]*\">[\u4e00-\u9fa5\\w\\s\\d\\(\\)<>=/]*</span>[<>\\w\\d\\s=/]*',\\d,\\d,'\\d+-\\d+','[\u4e00-\u9fa5-\\d\\./]*',-?\\d,-?\\d,-?\\d,\\d+)"); //定义一个Regex对象实例

            //List<Bet007_HistoryVS> historylist = new List<Bet007_HistoryVS>();
            for (int i = 0; i < mc.Count; i++)
            {
                Bet007_HistoryVS historyvs = new Bet007_HistoryVS(mc[i].Value);
                analydata.historylist.Add(historyvs);
            }

            mc = Regex.Matches(matchdata, "var h_data=\\[.*\\];");// 主队近期战绩
            mc = Regex.Matches(mc[0].Value, "('\\d+-\\d+-\\d+',\\d+,'[\u4e00-\u9fa5]*','#[\\w]*',\\d+,'[<>\\w\\d\\s=/]*<span title=\"[\u4e00-\u9fa5\\s]*[:|：][\\w]*\">[\u4e00-\u9fa5\\w\\s\\(\\)]*</span>[\u4e00-\u9fa5\\(\\)]*',\\d+,'<span title=\"[\u4e00-\u9fa5\\s]*[:|：][\\w]*\">[\u4e00-\u9fa5\\w\\s]*</span>[<>\\w\\d\\s=/]*',\\d,\\d,'\\d+-\\d+','[\u4e00-\u9fa5-\\d\\./]*',-?\\d,-?\\d,-?\\d,\\d+)"); //定义一个Regex对象实例

            //List<Bet007_HistoryVS> hosthistorylist = new List<Bet007_HistoryVS>();
            for (int i = 0; i < mc.Count; i++)
            {
                Bet007_HistoryVS historyvs = new Bet007_HistoryVS(mc[i].Value);
                analydata.hosthistorylist.Add(historyvs);
            }

            mc = Regex.Matches(matchdata, "var a_data=\\[.*\\];");// 客队近期战绩
            mc = Regex.Matches(mc[0].Value, "('\\d+-\\d+-\\d+',\\d+,'[\u4e00-\u9fa5]*','#[\\w]*',\\d+,'[<>\\w\\d\\s=/]*<span title=\"[\u4e00-\u9fa5\\s]*[:|：][\\w]*\">[\u4e00-\u9fa5\\w\\s\\(\\)]*</span>[\u4e00-\u9fa5\\(\\)]*',\\d+,'<span title=\"[\u4e00-\u9fa5\\s]*[:|：][\\w]*\">[\u4e00-\u9fa5\\w\\s]*</span>[<>\\w\\d\\s=/]*',\\d,\\d,'\\d+-\\d+','[\u4e00-\u9fa5-\\d\\./]*',-?\\d,-?\\d,-?\\d,\\d+)"); //定义一个Regex对象实例

            //List<Bet007_HistoryVS> visthistorylist = new List<Bet007_HistoryVS>();
            for (int i = 0; i < mc.Count; i++)
            {
                Bet007_HistoryVS historyvs = new Bet007_HistoryVS(mc[i].Value);
                analydata.visthistorylist.Add(historyvs);
            }

            mc = Regex.Matches(matchdata, "var h2_data=\\[.*\\];");// 主队近期主场战绩
            mc = Regex.Matches(mc[0].Value, "('\\d+-\\d+-\\d+',\\d+,'[\u4e00-\u9fa5]*','#[\\w]*',\\d+,'[<>\\w\\d\\s=/]*<span title=\"[\u4e00-\u9fa5\\s]*[:|：][\\w]*\">[\u4e00-\u9fa5\\w\\s\\(\\)]*</span>[\u4e00-\u9fa5\\(\\)]*',\\d+,'<span title=\"[\u4e00-\u9fa5\\s]*[:|：][\\w]*\">[\u4e00-\u9fa5\\w\\s]*</span>[<>\\w\\d\\s=/]*',\\d,\\d,'\\d+-\\d+','[\u4e00-\u9fa5-\\d\\./]*',-?\\d,-?\\d,-?\\d,\\d+)"); //定义一个Regex对象实例

            //List<Bet007_HistoryVS> hostmatchhistorylist = new List<Bet007_HistoryVS>();
            for (int i = 0; i < mc.Count; i++)
            {
                Bet007_HistoryVS historyvs = new Bet007_HistoryVS(mc[i].Value);
                analydata.hostmatchhistorylist.Add(historyvs);
            }

            mc = Regex.Matches(matchdata, "var a2_data=\\[.*\\];");// 客队近期客场战绩
            mc = Regex.Matches(mc[0].Value, "('\\d+-\\d+-\\d+',\\d+,'[\u4e00-\u9fa5]*','#[\\w]*',\\d+,'[<>\\w\\d\\s=/]*<span title=\"[\u4e00-\u9fa5\\s]*[:|：][\\w]*\">[\u4e00-\u9fa5\\w\\s\\(\\)]*</span>[\u4e00-\u9fa5\\(\\)]*',\\d+,'<span title=\"[\u4e00-\u9fa5\\s]*[:|：][\\w]*\">[\u4e00-\u9fa5\\w\\s]*</span>[<>\\w\\d\\s=/]*',\\d,\\d,'\\d+-\\d+','[\u4e00-\u9fa5-\\d\\./]*',-?\\d,-?\\d,-?\\d,\\d+)"); //定义一个Regex对象实例

            //List<Bet007_HistoryVS> vistmatchhistorylist = new List<Bet007_HistoryVS>();
            for (int i = 0; i < mc.Count; i++)
            {
                Bet007_HistoryVS historyvs = new Bet007_HistoryVS(mc[i].Value);
                analydata.vistmatchhistorylist.Add(historyvs);
            }

            mc = Regex.Matches(matchdata, "<tr align=middle class=red_t1>[\"\u4e00-\u9fa5\\s\\d\\w=<>/\\[\\]\\.:]*</tr>");// 联赛主队名字和排名标题
            String hostteamname = null;
            if (mc.Count > 0)
            {
                mc = Regex.Matches(mc[0].Value, "<font class=vander16><b>([\u4e00-\u9fa5\\[\\]\\d\\w]*)</b></font>");
                if (mc.Count > 0)
                {
                    hostteamname = mc[0].Value;
                    Console.WriteLine(hostteamname);
                }
            }

            mc = Regex.Matches(matchdata, "<tr align=middle  class=red_t2>[''\u4e00-\u9fa5\\s\\d\\w=<>/]*</tr>");// 主队联赛积分排名
            //<td[''\\s\\d\\w=]*>[\u4e00-\u9fa5]*</td>
            for (int i = 0; i < mc.Count; i++)
            {
                MatchCollection mc2 = Regex.Matches(mc[i].Value, "<td[''\\s\\d\\w=]*>[\u4e00-\u9fa5]*</td>");// 排名列标题名称
                for (int ii = 0; ii < mc2.Count; ii++)
                {

                }

            }


            ////////////////////////////////////////////////////////////////////////

            mc = Regex.Matches(matchdata, "<tr align=middle class=blue_t1>[\"\u4e00-\u9fa5\\s\\d\\w=<>/\\[\\]\\.:]*</tr>");// 联赛客队名字和排名标题
            //<td[''\\s\\d\\w=]*>[\u4e00-\u9fa5]*</td>
            for (int i = 0; i < mc.Count; i++)
            {
                //<font class=vander16><b>([\u4e00-\u9fa5\\[\\]\\d\\w]*)</b></font>

            }

            mc = Regex.Matches(matchdata, "<tr align=middle  class=blue_t2>[''\u4e00-\u9fa5\\s\\d\\w=<>/]*</tr>");// 客队联赛积分排名
            //<td[''\\s\\d\\w=]*>[\u4e00-\u9fa5]*</td>
            for (int i = 0; i < mc.Count; i++)
            {
                MatchCollection mc2 = Regex.Matches(mc[i].Value, "<td[''\\s\\d\\w=]*>[\u4e00-\u9fa5]*</td>");// 排名列标题名称
                for (int ii = 0; ii < mc2.Count; ii++)
                {

                }

            }

            // 前40 是排名积分统计数据
            mc = Regex.Matches(matchdata, "<td (bgcolor=#FEFAF8|bgcolor=#FEFAF8 class=red|bgcolor=#FEFAF8 class=blue|bgcolor=#FEFAF8 class=red)>(?<data>[\u4e00-\u9fa5\\d\\w=\\s/<>%\\.-]*)</td>");// 主队数据读取
            StringBuilder databuilder = new StringBuilder();
            //List<Bet007_TeamSum> hostlist = new List<Bet007_TeamSum>();
            int count = 0;
            foreach (Match match in mc)
            {
                GroupCollection gc = match.Groups;
                databuilder.Append(gc["data"]);
                databuilder.Append(",");
                if (count > 8)
                {
                    Bet007_TeamSum sum = new Bet007_TeamSum(databuilder.ToString());
                    analydata.hostlist.Add(sum);
                    count = 0;
                    databuilder = new StringBuilder();
                }
                count++;

            }
            databuilder = new StringBuilder();
            count = 0;
            //List<Bet007_TeamSum> vistlist = new List<Bet007_TeamSum>();
            mc = Regex.Matches(matchdata, "<td (bgcolor=#F2F9FD|bgcolor=#F2F9FD class=red|bgcolor=#F2F9FD class=blue|bgcolor=#F2F9FD class=red)>(?<data>[\u4e00-\u9fa5\\d\\w=\\s/<>%\\.-]*)</td>");// 客队数据读取
            foreach (Match match in mc)
            {
                GroupCollection gc = match.Groups;
                databuilder.Append(gc["data"]);
                databuilder.Append(",");
                if (count > 8)
                {
                    Bet007_TeamSum sum = new Bet007_TeamSum(databuilder.ToString());
                    analydata.vistlist.Add(sum);
                    count = 0;
                    databuilder = new StringBuilder();
                }
                count++;

            }
            return mId;
        }
        
        /// <summary>
        /// 获取对阵记录,联赛排名积分等信息 结束调用
        /// </summary>
        /// <param name="asyncResult"></param>
        /// <returns></returns>
        public static void GetMatchHistoryDataOk(IAsyncResult asyncResult)
        {

        }

        public delegate void OnGetMatchEuropeOdds(String mId);

        public static void GetMatchEuropeOdds(String mId)
        {
            HttpWebRequest httprequest = (HttpWebRequest)WebRequest.Create("http://1x2.nowscore.com/" + mId + ".js");
            String data;
            httprequest.Referer = "http://1x2.bet007.com/oddslist/" + mId  + ".htm";
            //httprequest.ContentType = "text/javascript; charset=gb2312";
            //httprequest.ContentType = "text/html; charset=utf-8";
            HttpWebResponse response = null;
            try
            {
                response = (HttpWebResponse)httprequest.GetResponse();

                StreamReader sr = new StreamReader(response.GetResponseStream());
                // 得到赛事数据
                data = sr.ReadToEnd();
                sr.Close();
                response.Close();
            }
            catch (System.Exception ex)
            {
                Console.Write(ex.Message);
                return;
            }

            if (data.Length > 0)
            {
                Bet007_OddsAllcompany oddscompany = new Bet007_OddsAllcompany(data);

                Bet007_AnalysisData analydata = bet007_matchdataobj.bet007analydata[mId] as Bet007_AnalysisData;

                analydata.matchoddscompany = oddscompany;
                
               
            }
        }
        
        public static void GetMatchEuropeOddsOk(IAsyncResult asyncResult)
        {

        }
        
    }
}
